package org.sbbs.app.license.service.impl;

import org.sbbs.app.license.dao.LicenseInfoDao;
import org.sbbs.app.license.model.LicenseInfo;
import org.sbbs.app.license.service.LicenseInfoManager;
import org.sbbs.base.service.impl.BaseManagerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.googlecode.genericdao.search.Search;

@Service( "licenseInfoManager" )
public class LicenseInfoManagerImpl
    extends BaseManagerImpl<LicenseInfo, Long>
    implements LicenseInfoManager {
    LicenseInfoDao licenseInfoDao;

    @Autowired
    public LicenseInfoManagerImpl( LicenseInfoDao licenseInfoDao ) {
        super( licenseInfoDao );
        this.licenseInfoDao = licenseInfoDao;
    }

    /*
     * @Override public void enableProductInfo( String[] ids ) { this.updateDisabledFlag( ids, false ); }
     * @Override public void disableProductInfo( String[] ids ) { this.updateDisabledFlag( ids, true ); } private void
     * updateDisabledFlag( String[] ids, Boolean newflag ) { this.productInfoDao.updateDisabledFlag( ids, newflag ); }
     */

    @Override
    public LicenseInfo getCurrentUsedLicenseInfo( Long customerId ) {
        Search s = new Search();
        s.addFilterEqual( "customerInfo.customerInfoId", customerId );
        s.addFilterEqual( "currentUsed", true );
        LicenseInfo li = this.licenseInfoDao.searchUnique( s );
        return li;
    }

    public int getLicenseInfoCount( Long customerId ) {
        Search s = new Search();
        s.addFilterEqual( "customerInfo.customerInfoId", customerId );
        return this.licenseInfoDao.count( s );
    }

    @Override
    public void updateCurrentLicense( Long liId ) {
        
        this.licenseInfoDao.updateCurrentLicense(liId);
        // TODO Auto-generated method stub
        
    }
}
